extends PanelContainer



onready var edit_input = $ParagraphForm/value/edit
onready var type_op = $ParagraphForm/value/VBoxContainer/HBoxContainer/OptionButton


const template1 = {"type":1,"finish":false,"value":3,"next":false}
const template2 = {"type":1,"name":"信号名称","finish":false,"value":"发射的信号参数","next":false}
const template3 = {"type":3,"finish":false,"func":"调用方法","value": "这里是方法的参数","next":false}
const template4 = {
	"type":4,
	"finish":false,
	"value":{
		"file":"res://module/assets/audio/battle/vs/mus_vs_wild.mid",
		"type":"sound",
		"loop_start":1080,
		"repeat":false,
		"playing":false,
		"reset_volume_db":true 
	},
	"next":false
}

const template5 = {
	"type":5,
	"finish":true,
	"value": "",
	"next":false
}

const template6 = {
	"type":6,
	"finish":true,
	"value": "具体剧本文件名称 不用写后缀,默认txt",
	"next":false
}

const template7 = {
	"type":7,
	"finish":true,
	"value": {
		"path":"res://xx/xx/xx/xx.tscn",
		"meta":{}
	}
}


func _ready():
	update_help(0)


func get_help(id):
	var helps =  [
		{
			"desc": "代表不需要做任何操作，请删除右侧所有内容",
			"template": ""
		},{
			"desc": "现有对话项：1，2，3,4,5\n在1对话设置选择操作跳转2或3，常用于选择分支，比如恢复中心对话",
			"template": JSON.print(template1, "\t")
		},
		{
			"desc": "调用信号,做更加复杂的事情",
			"template": JSON.print(template2, "\t")
		},
		{
			"desc": "调用提供方法，做更加复杂的事情",
			"template": JSON.print(template3,"\t")
		},
		{
			"desc": "播放音乐:\ntype:background/sound\nloop_start:循环的开始位置\nrepeat: 音量从小到大，type:background生效\nplaying: 是否立即播放sound有效",
			"template": JSON.print(template4,"\t")
		},
		{
			"desc": "用于在有选择对话里使用,选择后跳转另一对话",
			"template": JSON.print(template5,"\t")
		},
		{
			"desc": "对话过程中突然进入某个剧情或者是在选择了某一个选项后进入剧情，就需要此功能",
			"template": JSON.print(template6,"\t")
		},
		{
			"desc": "打开UI，比如选择初始宝可梦，商店等等",
			"template": JSON.print(template7, "\t")
		},
	]
	
	
	return helps[id]
	

func update_help(id, template=false):
	if id < 0 or id > 7:
		id = 0
	
	var help =  get_help(id)
	$ParagraphForm/value/VBoxContainer/Label.text = help["desc"]
	


func set_data(data):
	if data:
		edit_input.text = JSON.print(data,"\t")
	


 # 将当前组件数据构建为元数据
func get_data():
	return str2var(edit_input.text)


func _on_OptionButton_item_selected(index):
	update_help(type_op.get_selected_id())


func _on_useTemplate_button_up():
	var id = type_op.get_selected_id()
	if id < 0 or id > 7:
		id = 0
	
	var help =  get_help(id)
	edit_input.text = help["template"]
